<template>
	<view class="content">
		<view class="left-bottom-sign"></view>
		<view class="back-btn icon fanhui" @click="toBack"></view>
		<view class="right-top-sign"></view>
		<!-- 设置白色背景防止软键盘把下部绝对定位元素顶上来盖住输入框等 -->
		<view class="wrapper">
			<view class="left-top-sign">LOGIN</view>
			<view class="welcome">
				<!--#ifdef MP-WEIXIN-->
				<open-data type="userNickName"></open-data>,您好！
				<!--#endif-->
				<!--#ifdef MP-TOUTIAO-->
				尊敬的用户,您好！
				<!--#endif-->
			</view>
			<view class="help">为了更好的为您提供服务,请登录后使用.</view>
			<view class="avatar">
				<view class="img">
					<!--#ifdef MP-WEIXIN-->
					<open-data type="userAvatarUrl"></open-data>
					<!--#endif-->
					<!--#ifdef MP-TOUTIAO-->
					<img class="img" src=""/>
					<!--#endif-->
				</view>
			</view>
			<button class="confirm-btn" type="primary" :disabled="isDisabled" openType="getPhoneNumber" @getphonenumber="getPhoneNumber">一键登录</button>
		</view>
		<view class="service-section">
			<text @click="toRead">服务声明</text>
			<text @click="toHelp">技术支持</text>
		</view>
		
	</view>
</template>

<script>
	export default{
		data() {
		    return {
				isDisabled : false,
				code : ''
		    }
		},
		onLoad() {
			//#ifdef MP
			uni.hideShareMenu()
			//#endif
			this.getCode()
		},
		methods: {
			toBack(){
				uni.navigateBack({})
			},
			toRead(){
				uni.showToast({
					title: '阅读',
					icon: 'none',
					duration: 2000
				})
			},
			getCode(){
				let that = this
				//#ifdef MP-WEIXIN
				let provider = 'weixin'
				//#endif
				//#ifdef MP-TOUTIAO
				let provider = 'toutiao'
				//#endif
				uni.login({
					provider: provider,
					success: function (loginRes) {
						if(loginRes.errMsg == 'login:ok'){
							that.code = loginRes.code
						}
					}
				})
			},
			async getPhoneNumber(res) {
				this.isDisabled = true
				let info = res.detail
				//#ifdef MP-WEIXIN
				let provider = 'weixin'
				//#endif
				//#ifdef MP-TOUTIAO
				let provider = 'toutiao'
				//#endif
				if ("getPhoneNumber:ok" == info.errMsg) {
					let token = await this.$api('POST','user',{provider:provider,code:this.code,encryptedData:info.encryptedData,iv:info.iv,spread_id:uni.getStorageSync('spread_id')})
					if(token){
						uni.setStorageSync('token',token)
						let pages = getCurrentPages()
						if(pages.length > 1){
							let page = pages[pages.length - 2]
							page.onPullDownRefresh()
							this.toBack()
						}else{
							uni.reLaunch({url:'/pages/tabBar1'})
						}
					}
				}
				this.isDisabled = false
			},
			toHelp (){
				uni.setClipboardData({
				    data: 'cnzkai',
				    success: function () {
						uni.showToast({
							title: '技术人员微信号复制成功,请在微信中粘贴查找.',
							icon: 'none',
							duration: 5000
						})
				    }
				})
			}
		}
	}
</script>

<style lang='scss'>
	.content{
		background: #fff;
		height: 100vh;
		overflow: hidden;
	}
	.wrapper{
		padding-top: 115px;
		position:relative;
		z-index: 90;
		background: #fff;
		padding-bottom: 40upx;
	}
	.back-btn{
		position:absolute;
		left: 40upx;
		z-index: 9999;
		padding-top: var(--status-bar-height);
		top: 40upx;
		font-size: 40upx;
		color: $font-color-dark;
	}
	.left-top-sign{
		font-size: 120upx;
		color: $page-color-base;
		position:relative;
		left: -16upx;
	}
	.right-top-sign{
		position:absolute;
		top: 80upx;
		right: -30upx;
		z-index: 95;
		&:before, &:after{
			display:block;
			content:"";
			width: 400upx;
			height: 80upx;
			background: #b4f3e2;
		}
		&:before{
			transform: rotate(50deg);
			border-radius: 0 50px 0 0;
		}
		&:after{
			position: absolute;
			right: -198upx;
			top: 0;
			transform: rotate(-50deg);
			border-radius: 50px 0 0 0;
			/* background: pink; */
		}
	}
	.left-bottom-sign{
		width: 200upx;
		height: 200upx;
		border-radius:0 100% 0 0;
		border-top: solid 100upx #d0d1fd;
		border-right: solid 100upx #d0d1fd;
		position:absolute;
		left: 0;
		bottom: 0;
	}
	.welcome{
		position:relative;
		left: 50upx;
		top: -90upx;
		font-size: 46upx;
		color: #555;
		text-shadow: 1px 0px 1px rgba(0,0,0,.3);
	}
	.help{
		position:relative;
		left: 80upx;
		top: -80upx;
		font-size: 24upx;
		color: $uni-color-primary;
	}
	.avatar{
		margin: 30upx;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	.avatar .img{
		width: 300upx;
		height: 300upx;
		overflow:hidden;
		display: block;
		border-radius: 50%;
		border: 2px solid #fff;
		box-shadow: 3px 3px 10px rgba(0, 0, 0, 0.2);
	}
	.confirm-btn{
		width: 630upx;
		height: 76upx;
		line-height: 76upx;
		border-radius: 50px;
		margin-top: 70upx;
		background: $uni-color-primary;
		color: #fff;
		font-size: $font-lg;
		&:after{
			border-radius: 100px;
		}
	}
	.service-section{
		position:absolute;
		left: 0;
		bottom: 50upx;
		width: 100%;
		font-size: $font-sm+2upx;
		color: $font-color-base;
		text-align: center;
		text{
			color: $font-color-spec;
			margin-left: 10upx;
		}
	}
</style>
